package com.nuoniu.sibanyun.controller.system;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.AgreementDto;
import com.nuoniu.sibanyun.entity.dto.AgreementSearchDto;
import com.nuoniu.sibanyun.service.ISysAgreementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-08-31
 */
@RestController
@RequestMapping("/sys/agreement")
@Api(value="协议管理 ",tags={"协议管理","系统管理"})
public class SysAgreementController extends BaseController {

    @Autowired
    private ISysAgreementService sysAgreementService;


    @GetMapping("/list")
    @ApiOperation(value="协议集合",notes="协议集合")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult list(){
        return HttpResult.ok(sysAgreementService.last());
    }

    @GetMapping("/historyList")
    @ApiOperation(value="协议历史集合",notes="协议历史集合")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult historyList(AgreementSearchDto agreementSearchDto){
        return HttpResult.ok(sysAgreementService.historyList(agreementSearchDto));
    }

    @PreAuthorize("'system' == authentication.principal ")
    @PostMapping("/save")
    @ApiOperation(value="保存协议",notes="保存协议")
    public HttpResult save(@RequestBody AgreementDto agreementDto){
        return HttpResult.ok(sysAgreementService.saveAgreement(agreementDto));
    }

}
